package com.songwo.util;

import com.songwo.core.primary.entity.system.SysUser;
import com.songwo.core.service.system.SysUserService;
import org.apache.shiro.SecurityUtils;

/**
 * @author zhongzheng
 * @description 用户工具类
 * @date 2018/5/29 15:48
 */
public class UserUtils {

//    static SysUserService sysUserService = SpringContextHolder.getBean(SysUserService.class);

    public static SysUser getUser() {
        SysUser sysUser = new SysUser();
        Object o = SecurityUtils.getSubject().getPrincipal();
        if (o != null) {
            sysUser = findSysUserByName(o.toString());
        }
        return sysUser;
    }

    public static Long getUserId() {
        return getUser().getId();
    }

    public static SysUser findSysUserByName(String loginName) {
        SysUserService sysUserService = SpringContextHolder.getBean(SysUserService.class);
        return sysUserService.findSysUserByName(loginName);
    }
}
